var http = require('http');

var co = require('co')
var request = require('request');

const getRepoData = (options) => {
  return new Promise((resolve, reject) => {
    request(options, (err, res, body) => {
      if (err) {
        reject(err);
      }
      resolve(body);
    });
  });
};

var req = async () => {
  
  // var request = co.wrap(request);
  var da = await getRepoData('http://www.baidu.com');
   console.log(da);
  // return da;
	// request('http://www.baidu.com', function (error, res, body) {
	//   console.log('error:', error); // Print the error if one occurred
	//   console.log('statusCode:', res && res.statusCode); // Print the response status code if a response was received
	//   console.log('body:', body); // Print the HTML for the Google homepage.
	  
	// });
};


http.createServer(function (request, response) {

	// 发送 HTTP 头部 
	// HTTP 状态值: 200 : OK
	// 内容类型: text/plain
	response.writeHead(200, {'Content-Type': 'text/plain'});
	
	req();
    //  console.log(data);
     // response.end("data");

	// 发送响应数据 "Hello World"
	
}).listen(8888);

// 终端打印如下信息
console.log('Server running at http://127.0.0.1:8888/');